
/*******************************************
Analyses of the BHPS/Understanding Society Data
Tables OB2 & OB3, Figure OB8
********************************************/

/*************************************
First loads the Understanding Society Data
Then merges it with the BHPS data
Then keeps only those cases in both 
(i.e., drops those in BHPS but not US and those in US but not BHPS
**************************************/

clear 
*US Data
use "c_indresp.dta"
*Merge with BHPS
merge 1:1 pidp using "bo_indresp.dta" 

*Just focuses on those in both waves: 
keep if _merge==3

/*************************************
Big Five
Asked whether statement applies to self. 
1 = does not apply to me at all, 7 = applies to me perfectly
-9=missing, -8=inapplicable, -7=proxy, -2=refusal, -1=don't know

Following syntax recodes the measures, looks at reliability indices, and creates average scores
**************************************/

***Extraversion: talkative; sociable; reserve (need to reverse)

recode c_scptrt5e1 bo_scptrt5e1 c_scptrt5e2 bo_scptrt5e2 (-9/-1 =.) , gen(us_talkative bhps_talkative us_sociable bhps_sociable) 
recode c_scptrt5e3 bo_scptrt5e3 (-9/-1=.) (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1), gen(us_reserved bhps_reserved)

pwcorr us_talkative us_sociable us_reserved
alpha us_talkative us_sociable us_reserved, item
	*alpha = 0.61; lower correlation due to the reverse coded item

pwcorr bhps_talkative bhps_sociable bhps_reserved
alpha bhps_talkative bhps_sociable bhps_reserved, item
	*alpha = 0.55

egen bhps_extra = rowmean(bhps_talkative bhps_sociable bhps_reserved)
egen us_extra = rowmean(us_talkative us_sociable us_reserved)

***Openness: original, values artistic experiences, active imagination

recode c_scptrt5o2 bo_scptrt5o2 c_scptrt5o1 bo_scptrt5o1 c_scptrt5o3 bo_scptrt5o3 (-9/-1 =.),  ///
	gen(us_artistic bhps_artistic us_original bhps_original us_imagination bhps_imagination)

alpha us_artistic  us_original  us_imagination 
	*0.67
alpha bhps_artistic bhps_original bhps_imagination
	*68
	
egen us_open = rowmean( us_artistic  us_original  us_imagination )
egen bhps_open = rowmean(bhps_artistic bhps_original bhps_imagination)

	
***Conscientiousness: thorough,lazy (reverse), efficiently
recode c_scptrt5c1 bo_scptrt5c1 c_scptrt5c3 bo_scptrt5c3 (-9/-1=.), gen(us_thorough bhps_thorough us_efficient bhps_efficient)
recode c_scptrt5c2 bo_scptrt5c2 (-9/-1=.) (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1), gen(us_lazy bhps_lazy)

alpha us_thorough us_efficient us_lazy 
	*0.53
alpha bhps_thorough bhps_efficient bhps_lazy
	*0.52
	
egen us_cons = rowmean(us_thorough us_efficient us_lazy)
egen bhps_cons = rowmean(bhps_thorough bhps_efficient bhps_lazy)
	

***Agreeableness: rude (reverse), forgiging, considerate
recode c_scptrt5a1 bo_scptrt5a1 (-9/-1=.) (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1), gen(us_rude bhps_rude)
recode c_scptrt5a2 bo_scptrt5a2 c_scptrt5a3 bo_scptrt5a3 (-9/-1=.), gen(us_forgiving bhps_forgiving us_kind bhps_kind)

alpha us_rude  us_forgiving  us_kind 
	*0.56
alpha bhps_rude bhps_forgiving bhps_kind	
	*0.52

egen us_agree = rowmean( us_rude  us_forgiving  us_kind )
egen bhps_agree = rowmean(bhps_rude bhps_forgiving bhps_kind)
	
***Neuroticism/Emotional Stability: worries, gets nervous, relaxed (reverse)

recode c_scptrt5n1 bo_scptrt5n1 c_scptrt5n2 bo_scptrt5n2 (-9/-1=.), gen(us_worries bhps_worries us_nervous bhps_nervous)
recode c_scptrt5n3 bo_scptrt5n3 (-9/-1=.) (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1), gen(us_relaxed bhps_relaxed)

alpha us_worries  us_nervous  us_relaxed 
	*0.72
alpha bhps_worries bhps_nervous bhps_relaxed
	*0.68

egen us_neu = rowmean(us_worries  us_nervous  us_relaxed )
egen bhps_neu = rowmean(bhps_worries bhps_nervous bhps_relaxed)

*********Factor Scores
egen nmis = rowmiss(us_artistic  us_original  us_imagination bhps_artistic bhps_original bhps_imagination ///
	us_talkative us_sociable us_reserved  bhps_talkative bhps_sociable bhps_reserved ///
	us_thorough us_efficient us_lazy  bhps_thorough bhps_efficient bhps_lazy ///
	us_rude  us_forgiving  us_kind bhps_rude bhps_forgiving bhps_kind ///
	us_worries  us_nervous  us_relaxed  bhps_worries bhps_nervous bhps_relaxed)
	

***Combined Model

sem (OPEN2 -> us_artistic  us_original  us_imagination) ///
	(OPEN1 -> bhps_artistic bhps_original bhps_imagination) ///
	(EXTRA2 -> us_talkative us_sociable us_reserved) ///
	(EXTRA1 -> bhps_talkative bhps_sociable bhps_reserved) ///
	(CONS2 -> us_thorough us_efficient us_lazy ) ///
	(CONS1 -> bhps_thorough bhps_efficient bhps_lazy) ///
	(AGREE2 -> us_rude  us_forgiving  us_kind) ///
	(AGREE1 -> bhps_rude bhps_forgiving bhps_kind) ///
	(NEU2 -> us_worries  us_nervous  us_relaxed ) ///
	(NEU1 -> bhps_worries bhps_nervous bhps_relaxed), method(mlmv)

estat gof, stats(all) 
	*cfi = 0.758
	*rmsea = 0.074
	*tli = 0.708

*Factor scores

predict us_open_f2 bhps_open_f2 ///
	us_extra_f2 bhps_extra_f2 ///
	us_cons_f2 bhps_cons_f2 ///
	us_agree_f2 bhps_agree_f2 ///
	us_neu_f2 bhps_neu_f2, latent(OPEN2 OPEN1 EXTRA2 EXTRA1 CONS2 CONS1 AGREE2 AGREE1 NEU2 NEU1)
	

*Removes predicted values in cases where the respondent did not answer *any* question
	
foreach var in us_open_f2 bhps_open_f2 ///
	us_extra_f2 bhps_extra_f2 ///
	us_cons_f2 bhps_cons_f2 ///
	us_agree_f2 bhps_agree_f2 ///
	us_neu_f2 bhps_neu_f2 {
	replace `var' = . if nmis==30
}	

****Correlations (Table OB2)

foreach var in open extra cons agree neu {
	pwcorr us_`var'_f2 bhps_`var'_f2
}


***Change in Factor Scores (Common Model)

gen open_diff = us_open_f2 - bhps_open_f2
	label var open_diff "Change Open. to Experience"
gen cons_diff = us_cons_f2 - bhps_cons_f2
	label var cons_diff "Change Conscientiousness"
gen extra_diff = us_extra_f2 - bhps_extra_f2
	label var extra_diff "Change Extraveresion"
gen agree_diff = us_agree_f2 - bhps_agree_f2
	label var agree_diff "Change Agreeableness"
gen neu_diff = us_neu_f2 - bhps_neu_f2
	label var neu_diff "Change Neuroticism"


*******Figure OB8: Distributions

preserve 
rename open_diff diff1
rename cons_diff diff2
rename extra_diff diff3
rename agree_diff diff4
rename neu_diff diff5
gen id=_n
reshape long diff, i(id) j(trait)
label def tra 1 "Openness to Experience" 2 "Conscientiousness" 3 "Extraversion" 4 "Agreeableness" 5 "Neuroticism"
label values trait tra
histogram diff, by(trait, note("")) scheme(plottig) fraction xtitle("")
graph export "trait_change.png", replace width(1500) height(1100)
restore

/********************************
Duty & Controls/Other Vars
*********************************/

*civicduty
recode c_civicduty (-9/-1=.) (1=5) (2=4) (3=3) (4=2) (5=1) (6=.), gen(duty)

*voted
recode bo_vote7 (-9/-1=.) (1=1 "Voted" ) (2 = 0 "Did Not Vote") (3=.), gen(bhps_voted)

*age
recode bo_age (-9/-1 =.), gen(age)
label var age "Age in Yrs"

*sex
recode bo_sex (-9/-1=.) (1=0 "Male") (2=1 "Female"), gen(female)
label var female "Resp. Sex"

*household size (2005)
gen hsize_ln = ln(bo_hhsize)
label var hsize_ln "LN of Household Size (2005)"

*svyset
svyset c_psu [pweight=c_indin01_lw], strata(c_strata)



/********************************
Analyses
*********************************/

label var bhps_cons_f2 "Conscientiousness" 
label var bhps_extra_f2 "Extraversion"
label var bhps_open_f2 "Openness to Experience"
label var bhps_agree_f2 "Agreeableness"
label var bhps_neu_f2 "Neuroticism"

eststo clear
eststo: svy: regress duty open_diff cons_diff extra_diff agree_diff neu_diff c.age i.female c.hsize_ln
esttab using "panel_results.rtf", replace nobaselevels label onecell se r2 b(2) ///
	addnote("Models use survey weights.") ///
	title("{\b Table X}: Personality Traits and Voting as a Duty")
	
	
